import Login from './Login'
import Flowers from './Flowers'
import { Redirect, Switch } from 'react-router';
import { BrowserRouter as Router, Link, Route } from 'react-router-dom';

const App = () => {

    const LoginPage = () => {
        return <Login />
    }
    const FlowerPage = () => {
        return <Flowers />
    }
    const JudgFlag = ({ component: F }) => {
        const DATA = {
            username: localStorage.getItem('username'),
            passwd: localStorage.getItem('passwd')
        }
        console.log(DATA.username);//null
        console.log(DATA.passwd);//null

        if (DATA.username === null && DATA.passwd === null) {
            console.log('/login')
            return (
                <Redirect to={{
                    pathname: '/login'
                }}
                />
            );
        } else {
            console.log('/')
            return <F />;
        }
    }
    return (<div>
        <Router>
            <Switch>
                <JudgFlag exact component={FlowerPage} path='/' />
                <Route path='/login' component={LoginPage} />
            </Switch>
        </Router>
    </div>)
}
export default App;